<?php
ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\model\activity\BizProjectCustomerModel;
use Biz\model\activity\BizProjectResponsibilityModel;

$rows = BizProjectCustomerModel::dataSelect(BizProjectCustomerModel::statusCondition());
var_dump($rows);
foreach ($rows as $row) {
    $id = $row['id'];
    $sellers = ["zhangfenglin"];
    BizProjectCustomerModel::action(function () use ($id, $sellers) {
        $exists = BizProjectResponsibilityModel::existsList($id, BizProjectResponsibilityModel::RESPONSIBILITY_MODULE_CUSTOMER);
        $find = [];
        foreach ($exists as $v) {
            $find[$v['admin_id']] = $v;
        }
        $rows = [];
        foreach ($sellers as $admin_id) {
            if (empty($admin_id)) continue;
            if (isset($find[$admin_id])) {
                $status = $find[$admin_id]['status'];
                if (!BizProjectResponsibilityModel::isNormal($status)) {
                    $rows[] = ['id' => $find[$admin_id]['id'], 'status' => BizProjectResponsibilityModel::normalStatus()];
                }
                unset($find[$admin_id]);
            } else {
                $rows[] = ['project_id' => $id, 'type' => BizProjectResponsibilityModel::RESPONSIBILITY_TYPE_SELLER, 'module' => BizProjectResponsibilityModel::RESPONSIBILITY_MODULE_CUSTOMER,'admin_id' => $admin_id];
            }
        }
        foreach ($find as $item) {
            if (BizProjectResponsibilityModel::isNormal($item['status'])) {
                $rows[] = ['id' => $item['id'], 'status' => BizProjectResponsibilityModel::delStatus()];
            }
        }

        foreach ($rows as $row) {
            BizProjectResponsibilityModel::addData($row);
        }
    });
}
